/**
 * <copyright>
 * </copyright>
 *

 */
package org.eclipse.gittab.gitTabDsl.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.gittab.gitTabDsl.GitTabDslPackage;
import org.eclipse.gittab.gitTabDsl.GuitarStr;
import org.eclipse.gittab.gitTabDsl.Tuning;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Tuning</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.eclipse.gittab.gitTabDsl.impl.TuningImpl#getName <em>Name</em>}</li>
 *   <li>{@link org.eclipse.gittab.gitTabDsl.impl.TuningImpl#getFrets <em>Frets</em>}</li>
 *   <li>{@link org.eclipse.gittab.gitTabDsl.impl.TuningImpl#getStrings <em>Strings</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TuningImpl extends MinimalEObjectImpl.Container implements Tuning
{
  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * The default value of the '{@link #getFrets() <em>Frets</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFrets()
   * @generated
   * @ordered
   */
  protected static final int FRETS_EDEFAULT = 0;

  /**
   * The cached value of the '{@link #getFrets() <em>Frets</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFrets()
   * @generated
   * @ordered
   */
  protected int frets = FRETS_EDEFAULT;

  /**
   * The cached value of the '{@link #getStrings() <em>Strings</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStrings()
   * @generated
   * @ordered
   */
  protected EList<GuitarStr> strings;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected TuningImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return GitTabDslPackage.Literals.TUNING;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName()
  {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName)
  {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, GitTabDslPackage.TUNING__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public int getFrets()
  {
    return frets;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setFrets(int newFrets)
  {
    int oldFrets = frets;
    frets = newFrets;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, GitTabDslPackage.TUNING__FRETS, oldFrets, frets));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<GuitarStr> getStrings()
  {
    if (strings == null)
    {
      strings = new EObjectContainmentEList<GuitarStr>(GuitarStr.class, this, GitTabDslPackage.TUNING__STRINGS);
    }
    return strings;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TUNING__STRINGS:
        return ((InternalEList<?>)getStrings()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TUNING__NAME:
        return getName();
      case GitTabDslPackage.TUNING__FRETS:
        return getFrets();
      case GitTabDslPackage.TUNING__STRINGS:
        return getStrings();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TUNING__NAME:
        setName((String)newValue);
        return;
      case GitTabDslPackage.TUNING__FRETS:
        setFrets((Integer)newValue);
        return;
      case GitTabDslPackage.TUNING__STRINGS:
        getStrings().clear();
        getStrings().addAll((Collection<? extends GuitarStr>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TUNING__NAME:
        setName(NAME_EDEFAULT);
        return;
      case GitTabDslPackage.TUNING__FRETS:
        setFrets(FRETS_EDEFAULT);
        return;
      case GitTabDslPackage.TUNING__STRINGS:
        getStrings().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case GitTabDslPackage.TUNING__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case GitTabDslPackage.TUNING__FRETS:
        return frets != FRETS_EDEFAULT;
      case GitTabDslPackage.TUNING__STRINGS:
        return strings != null && !strings.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(", frets: ");
    result.append(frets);
    result.append(')');
    return result.toString();
  }

} //TuningImpl
